<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>
  <script>
    
    // axios({
    //   url:'www.baidu.com',//路径可以拼params参数数据，也可以拼query参数
    //   method:'POST/GET/PUT/DELETE',
    //   params:{}, //query参数
    //   data:{},//请求体参数
    // })
    // axios.get(url,{params:{name:'tom',age:12}})
    // axios.post(url,data对象)
    //添加请求拦截器：发送请求执行
    axios.interceptors.request.use((config)=>{
      console.log('请求拦截器执行。。。',config);
      //config.headers.token='xxxxa123213'
      return config
    })
    //添加响应拦截器
    axios.interceptors.response.use(
      response=>{
        console.log('响应拦截器的成功的回调',response.data);
        return response.data
      },
      error=>{
        console.log('响应拦截器失败的回调')
        throw error
        //return Promise.reject(error);
      }
    )
    axios.get("https://api.github.com/search/users",{
      params:{q:'zxfjd3g'}
    })
    //axios.get('https://api.github.com/search/users?q=a')
    .then(
      data =>{
        console.log('成功了',data)
      },
      error=>{
        console.log('失败了',error.message)
      }
    )
  </script>
</body>
</html>